Completed
Push — master ( 379ba1...581bac )
by Maxence
03:40
created

Files_FullTextSearch.onResultClose   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
nc 1
nop 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 3 1
1
/*
2
 * Files_FullTextSearch - Index the content of your files
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2018
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
27
/** global: OCA */
28
29
const fullTextSearch = OCA.FullTextSearch.api;
0 ignored issues
show
Backwards Compatibility introduced by
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
30
31
32
var elements = {
33
	old_files: null,
34
	search_result: null,
35
	current_dir: ''
36
};
37
38
39
const Files_FullTextSearch = function () {
0 ignored issues
show
Backwards Compatibility introduced by
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
40
	this.init();
41
};
42
43
44
Files_FullTextSearch.prototype = {
45
46
	init: function () {
47
		var self = this;
48
49
		elements.old_files = $('#app-content-files');
50
51
		elements.search_result = $('<div>');
52
		elements.search_result.insertBefore(elements.old_files);
53
54
		fullTextSearch.setEntryTemplate(self.generateTemplateEntry());
55
		fullTextSearch.setResultContainer(elements.search_result);
56
		fullTextSearch.initFullTextSearch('files', 'files', self);
57
	},
58
59
60
	generateTemplateEntry: function () {
61
62
		var divLeft = $('<div>', {class: 'result_entry_left'});
63
		divLeft.append($('<div>', {id: 'title'}));
64
		divLeft.append($('<div>', {id: 'line1'}));
65
		divLeft.append($('<div>', {id: 'line2'}));
66
67
		var divRight = $('<div>', {class: 'result_entry_right'});
68
		divRight.append($('<div>', {id: 'score'}));
69
70
		var divDefault = $('<div>', {class: 'result_entry_default'});
71
		divDefault.append(divLeft);
72
		divDefault.append(divRight);
73
74
		return $('<div>').append(divDefault);
75
	},
76
77
78
	onEntryGenerated: function (entry) {
0 ignored issues
show
Unused Code introduced by
The parameter entry is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
79
	},
80
81
82
	onResultDisplayed: function () {
83
		elements.old_files.fadeOut(150, function () {
84
			elements.search_result.fadeIn(150);
85
		});
86
	},
87
88
89
	onSearchRequest: function (data) {
90
		if (data.options.files_within_dir === '1') {
91
			var url = new URL(window.location.href);
0 ignored issues
show
Bug introduced by
The variable URL seems to be never declared. If this is a global, consider adding a /** global: URL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
92
			data.options.files_within_dir = url.searchParams.get("dir");
93
		}
94
	},
95
96
97
	onResultClose: function () {
98
		elements.search_result.fadeOut(150, function () {
99
			elements.old_files.fadeIn(150);
100
		});
101
	},
102
103
104
	onSearchReset: function () {
105
		elements.search_result.fadeOut(150, function () {
106
			elements.old_files.fadeIn(150);
107
		});
108
	}
109
110
};
111
112
113
OCA.FullTextSearch.Files = Files_FullTextSearch;
114
115
$(document).ready(function () {
116
	OCA.FullTextSearch.navigate = new Files_FullTextSearch();
117
});
118
119
120
121